package goover.unit06;

public class RunnableDemo06 {
    public static void main(String[] args){
        Test03 t = new Test03();
        Thread t1 = new Thread(t,"窗口1：");
        Thread t2 = new Thread(t,"窗口2：");
        Thread t3 = new Thread(t,"窗口3：");
        Thread t4 = new Thread(t,"窗口4：");
        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
class Test03 implements Runnable{
    private int sum = 100;
    private  Object lock = new Object();
    @Override
    public void run() {
        while (true){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (lock){
                if(sum > 0){
                    System.out.println(Thread.currentThread().getName() + "票号：" + sum--);
                }
            }
        }
    }
}